1a3e4b
@@ -399,6 +399,17 @@
private void registerCurrentOperationLog() {
 
   private synchronized void cleanup(OperationState state) throws HiveSQLException {
     setState(state);
+
+    if (shouldRunAsync()) {
+      Future<?> backgroundHandle = getBackgroundHandle();
+      if (backgroundHandle != null) {
+        boolean success = backgroundHandle.cancel(true);
+        if (success) {
+          LOG.info("The running operation has been successfully interrupted.");
+        }
+      }
+    }
+
     if (driver != null) {
       driver.close();
       driver.destroy();
@@ -413,13 +424,6 @@
private synchronized void cleanup(OperationState state) throws HiveSQLException
       ss.deleteTmpErrOutputFile();
     }
 
-    if (shouldRunAsync()) {
-      Future<?> backgroundHandle = getBackgroundHandle();
-      if (backgroundHandle != null) {
-        backgroundHandle.cancel(true);
-      }
-    }
-
     // Shutdown the timeout thread if any, while closing this operation
     if ((timeoutExecutor != null) && (state != OperationState.TIMEDOUT) && (state.isTerminal())) {
       timeoutExecutor.shutdownNow();
